package com.example.springboot_code_read.annotationMetadata;

import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

public class AnnotationMetadataDemoByASM {

    public static void main(String[] args) throws IOException {

        SimpleMetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();

        MetadataReader metadataReader = readerFactory.getMetadataReader("com.example.springboot_code_read.bean.MyBean");

        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

        System.out.println("annotationMetadata class is " + annotationMetadata.getClass());

        boolean annotated = annotationMetadata.isAnnotated(Component.class.getName());

        System.out.println("annotation is Component " + annotated);

        if (annotated) {
            Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(Component.class.getName());
            System.out.println("annotation value is " + annotationAttributes.get("value"));
        }


    }

}
